﻿using Serilog;
using Serilog.Core;
using Serilog.Events;
using Serilog.Formatting.Display;

public class CompanyNameEnricher : ILogEventEnricher
{
    private readonly string companyName;

    public CompanyNameEnricher(string companyName)
    {
        this.companyName = companyName;
    }

    public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
    {
        var replacedCompanyName = new string('*', companyName.Length);
        var propertyName = propertyFactory.CreateProperty("CompanyName", replacedCompanyName);
        logEvent.AddOrUpdateProperty(propertyName);
    }
}

public static class Program
{
    public static void Main()
    {
        var companyName = "WenTao";
        var logger = new LoggerConfiguration()
            .WriteTo.Console(formatter: new MessageTemplateTextFormatter("{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Properties} {Message}{NewLine}{Exception}"))
            .Enrich.With(new CompanyNameEnricher(companyName))
            .CreateLogger();

        logger.Information("This is a test log message.");

        logger.Dispose();
    }
}